package demo.DataStrucAndAlgo.SingletonPattern;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/7/30-07-30-9:16
 * @Description：demo.DataStrucAndAlgo.SingletonPattern   饿汉式单例模式
 */
/*
饿汉式单例模式
    不是懒初始化
    多线程安全
    易产生垃圾对象、类加载时就初始化，浪费内存
 */
public class SingleHangary {
    private static SingleHangary instance = new SingleHangary();

    private SingleHangary(){}

    public static SingleHangary getInstance(){
        return instance;
    }

    public void showMessage(){
        System.out.println("hello hello");
    }

    public static void main(String[] args) {
        SingleHangary single = SingleHangary.getInstance();
        SingleHangary single2 = SingleHangary.getInstance();
        System.out.println(single==single2);
        single.showMessage();
    }
}
